package com.shujia.controller;

import com.shujia.entity.Beans;
import com.shujia.entity.User;
import com.shujia.service.Hello;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.*;

@RestController
//@Controller
public class TestController {

    //基本类型+String类型+日期类型
    @Value("${name}")
    private String name;
    @Value("${age}")
    private int age;
    @Value("${sal}")
    private int sal;
    @Value("${bir}")
    private Date bir;
    @Value("${shuzu}")
    private int[] arr;
    @Value("${list1}")
    private List<String> list;
    @Value("#{${map1}}")
    private Map<String,String> map;

    @Autowired
    private User user;

    @Autowired
    private Hello hello;

    @Autowired
    private Beans beans;


    //使用url请求连接决定用户将来使用哪个方法
    //http/https://www.dsad.c/hello
    //localhost:8080/hello
    @RequestMapping("hello")
    public String sayHello() {
        hello.sayHello();
        Calendar c1 = beans.calendar();
        Date date = c1.getTime();

        //日期格式的转换
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        String s = sdf.format(date);
        System.out.println(Arrays.toString(arr));
        System.out.println(list);
        System.out.println(map);
        System.out.println(user);

        return "欢迎大家使用Springboot框架！！" + s+name+","+age+","+sal+","+bir;
    }

    @RequestMapping("hello2")
    public void sayNihao() {
//        return "你好！！";
        System.out.println("你好");
    }
}
